package org.come.until;

import java.awt.Font;
import java.io.File;
import java.io.FileInputStream;

public class FontUntil {

    public static Font loadFont(String fontFileName, float fontSize) { // 第一个参数是外部字体名，第二个是字体大小
        try {
            File file = new File(fontFileName);
            FileInputStream aixing = new FileInputStream(file);
            Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, aixing);
            Font dynamicFontPt = dynamicFont.deriveFont(fontSize);
            aixing.close();
            return dynamicFontPt;
        } catch (Exception e) {// 异常处理
            e.printStackTrace();
            return new Font("宋体", Font.PLAIN, 14);
        }
    }
    /** 获取汉仪小隶书简字体 */
    public static Font getHanYiFont(int fontSize) {
        Font font = loadFont("resource/font/HYF2GJM_0.TTF", fontSize);
        font = font.deriveFont(Font.LAYOUT_LEFT_TO_RIGHT+Font.BOLD);
        return font;
    }
    /** 汉仪楷体简 */
    public static Font getHYKTJFont(int fontSize) {
        Font font = loadFont("resource/font/HYC1GJM.TTF", fontSize);
        font = font.deriveFont(Font.BOLD);
        return font;
    }
    /** 汉仪隶书繁 */
    public static Font getHYLSFFont(int fontSize) {
    	Font font = loadFont("resource/font/篆书字体.TTF", fontSize);
    	font = font.deriveFont(Font.BOLD);
    	return font;
    }


    /**基础字体*/
    public static Font loadFont(String fontFileName) { // 第一个参数是外部字体名，第二个是字体大小
        try {
            File file = new File(fontFileName);
            FileInputStream aixing = new FileInputStream(file);
            Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, aixing);
            return dynamicFont;
        } catch (Exception e) {// 异常处理
            e.printStackTrace();
            return new Font("宋体", Font.PLAIN, 14);
        }
    }
}
